<template>
    <div class="vol_create van-safe-area-bottom"></div>
    <div class="vol_create foot van-safe-area-bottom">
      <div>
        <van-button size="small" type="primary" block class="mt-3" @click="clickAddSpeaker">添加讲者</van-button>
      </div>
    </div>

    <dialog-qr ref="refDialogQr"></dialog-qr>

    <van-action-sheet
        v-model:show="visible"
        :closeable="false"
        title="添加讲者"
        :actions="actions"
        cancel-text="取消"
        close-on-click-action
        @cancel="clickCancel"
        @select="clickSelect"
    />
</template>

<script setup>
import { ref, computed } from 'vue'
import router from '@/router'
import { useStore } from "vuex"

const store = useStore()
const visible = ref(false)
const refDialogQr = ref()
const userInfo = computed(() => store.getters['user/getUserInfo'])
const actions = [
    { name: '手动添加讲者', value: 'create' },
    { name: '讲者自行注册', value: 'qrcode', subname: '扫码注册' }
];

// 点击添加讲者
const clickAddSpeaker = () => {
    visible.value = true
}
// 点击取消
const clickCancel = () => visible.value = false
// 点击选择
const clickSelect = (item) => {
    switch (item.value) {
        case 'create':
            sessionStorage.removeItem('isScan');
            router.push(`/vol/detail-speaker?type=add&volunteer=${userInfo.value.id}`);
            break;
        case 'qrcode':
            refDialogQr.value.init(userInfo.value.invitationCode);
            break;
    }
}
</script>